
import 'dart:async';
import 'dart:convert';
import 'package:flutter_trip/models/home_model.dart';
import 'package:http/http.dart' as http;
import 'package:dio/dio.dart';

const String homeUrl ='https://www.devio.org/io/flutter_app/json/home_page.json';

class HomeDao{
  static Future<HomeModel> fetch1()async{
    var url = Uri.parse(homeUrl);
    final response = await http.get(url);
    if(response.statusCode==200){
      //中文乱码的问题
      Utf8Decoder utf8decoder = Utf8Decoder();
      var result = json.decode(utf8decoder.convert(response.bodyBytes));

      return HomeModel.fromJson(result);

    }else{
      throw Exception('加载首页信息失败');
    }
  }
  static Future<HomeModel> fetch()async{
    Dio dio = Dio(
    );
    var response = await dio.get(homeUrl);
    if(response.statusCode==200){
      //中文乱码的问题
      Utf8Decoder utf8decoder = Utf8Decoder();
      // var result = json.decode(utf8decoder.convert(response.bodyBytes));
      var result = response.data;

      return HomeModel.fromJson(result);

    }else{
      throw Exception('加载首页信息失败');
    }
  }

}

